package com.heatup.apt.management.controller;

import com.alibaba.fastjson.JSONObject;
import com.heatup.apt.management.service.SmslogService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
 * 短信发送管理
 * <P>File name : SmslogController.java </P>
 * <P>Author : fangxiaowen </P> 
 * <P>Date : 2016年10月17日 </P>
 */
@Controller
@RequestMapping("/system/smslog")
public class SmslogController extends BaseController{

	@Resource
	private SmslogService smslogService;
	
	/**
	 * 跳转到短信列表页面
	 *
	 * @return
	 */
    @RequestMapping(value = "/to_smslog_list")
    public ModelAndView to_user_list() {
        return new ModelAndView("smslog/smslog_list");
    }

    /**
     * 短信发送记录分页
     *
     * @param response
     * @param pageIndex
     * @param pageSize
     * @param mobile
     */
    @RequestMapping(value = "/smslog_list")
    public void sms_page_list(HttpServletResponse response,
                              @RequestParam int pageIndex,
                              @RequestParam int pageSize,
                              @RequestParam(required = false) String mobile){

//        SmsLog smsLog = new SmsLog();
//        if (StringUtils.isNotBlank(mobile)) {
//            smsLog.setMobile(mobile);
//        }
//        //查询参数
//        EntityWrapper<SmsLog> entityWrapper = new EntityWrapper<>();
//        entityWrapper.setEntity(smsLog);
//        entityWrapper.orderBy("send_time",false);//倒序排序
        Map<String,Object> paramsMap = new HashMap<>();
        paramsMap.put("mobile", mobile);
        if (pageIndex == 0 || pageIndex == 1) {
            pageIndex = 0;
        } else {
            pageIndex = (pageIndex - 1) * 10;
        }
        paramsMap.put("pageIndex", pageIndex);
        paramsMap.put("pageSize", pageSize);
        Map<String, Object> resultMap = smslogService.selectSmsLogPage(paramsMap);

        responseSendMsg(response, JSONObject.toJSONString(resultMap));

    }
   
}
